<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<?php
require "hrfuns.php";
Valid_Client();
$iSQL = GetSQL();
?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<title>Employee information</title>
<link rel="stylesheet" href="hr.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script src="hr.js"></script>
<script type="text/javascript">
<!--
function doAdd()
{
    if (confirm('确认添加吗？')) {
        frmAdd = document.forms['frmAddEmployee'];

        submitstr = 'Action=Add'
                 + '&EmId=' + frmAdd.elements['txtEmId'].value
                 + '&EmName=' + frmAdd.elements['txtEmName'].value
                 + '&EmDepart=' + frmAdd.elements['selDepart'].value
                 + '&EmClass=' + frmAdd.elements['txtClass'].value
                 + '&EmEnter=' + frmAdd.elements['txtEnter'].value
                 + '&EmBirth=' + frmAdd.elements['txtBirth'].value
                 + '&EmGender=' + frmAdd.elements['selGender'].value;

        var request = CreateHttpRequest();

        request.open('POST', 'eminfo_do.php', false);
        request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        request.send(submitstr);

        if (request.responseText.length > 0) 
            alert(request.responseText);
        else
            window.location.reload();
    }
}

function doDelete(em_id)
{
    frmDelete = document.forms['frm' + em_id];
    Employee = em_id + '(' + frmDelete.elements['txtEmName'].value + ')';

    if (confirm('确认删除员工 ' + Employee + '吗？')) {

        submitstr = 'Action=Delete'
                 + '&EmId=' + em_id;

        var request = CreateHttpRequest();

        request.open('POST', 'eminfo_do.php', false);
        request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        request.send(submitstr);

        if (request.responseText.length > 0) 
            alert(request.responseText);
        else
            window.location.reload();

    }
}

function doModify(em_id)
{
    frmMod = document.forms['frm' + em_id];
    Employee = em_id + '(' + frmMod.elements['txtEmName'].value + ')';

    if (confirm('确认修改员工 ' + Employee + '的信息吗？')) {

        submitstr = 'Action=Modify'
                 + '&EmId=' + em_id
                 + '&EmName=' + frmMod.elements['txtEmName'].value
                 + '&EmDepart=' + frmMod.elements['selDepart'].value
                 + '&EmClass=' + frmMod.elements['txtClass'].value
                 + '&EmEnter=' + frmMod.elements['txtEnter'].value
                 + '&EmBirth=' + frmMod.elements['txtBirth'].value
                 + '&EmGender=' + frmMod.elements['selGender'].value;

        var request = CreateHttpRequest();

        request.open('POST', 'eminfo_do.php', false);
        request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        request.send(submitstr);

        if (request.responseText.length > 0) 
            alert(request.responseText);
    }
}


-->
</script>
</head>

<body>
<form id="frmAddEmployee">
<table bgcolor=#c8c8c8 cellspacing=1 cellpadding=1 align="center">
<tr>
    <td>&nbsp;员工号：</td>
    <td><input type="text" id="txtEmId" class="input-box" maxlength=8/> </td>
    <td>&nbsp;姓名：</td>
    <td><input type="text" id="txtEmName" class="input-box" maxlength=8 /> </td>
    <td>&nbsp;所属部门：</td>
    <td><select id="selDepart" class="input-list">
<?php
    $lstDepart = GetDepartList($iSQL);
    foreach ($lstDepart as $depart) {
        echo "        <option value=\"" . $depart['depart_id'] . "\">" 
            . $depart['depart_name'] . "</option>\n";
    }
?>
    </select> </td>
    <td>&nbsp;班组：
    <td><input type="text" id="txtClass" class="input-s-box"
	       maxlength=1 value=""></td>
</tr>
<tr>
    <td>&nbsp;入职日期：</td>
    <td><input type="text" id="txtEnter" class="input-box" 
               maxlength=10 value="<?php
    $date = new DateTime(); 
    echo $date->format('Y-m-d');
?>"/>
    </td>
    <td>&nbsp; 出生日期：</td>
    <td><input type="text" id="txtBirth" class="input-box" 
               maxlength=10 value=""/>
    </td>
    <td>&nbsp; 性别：</td>
    <td><select id="selGender" class="input-list"> 
        <option value="男">男</option>
        <option value="女">女</option>
    </select> </td>
    <td colspan=2>
        <button type="button" onclick="doAdd()" value=" Add ">Add</button>
        <input type="reset" value=" Clear " />
    </td>
</tr>
</table>
</form>
<br />
<div id="header" style="background-color:#FFA500;clear:both;text-align:right;"
 onclick="window.location.assign('/hr')"><u>返回</u></div>

<table bgcolor=#c8c8c8 cellspacing=1 cellpadding=2 align="center">
<tr>
    <th>员工号</th>
    <th>姓  名</th>
    <th>部  门</th>
    <th>班  组</th>
    <th>入职日期</th>
    <th>出生日期</th>
    <th>性别</th>
    <th>&nbsp;</th>
</tr>
<?php
$sqlstr = "select em_id, em_name, em_depart_id, em_depart, em_enter"
        . ", em_class, em_birth, em_gender"
        . " from eminfo_v order by em_depart_id, em_id";
$resEm = $iSQL->query($sqlstr);

while ($row = $resEm->fetch_assoc()) {
    echo "<form id=\"frm" . $row["em_id"] . "\">\n";
    
    if ($row["em_depart_id"] == 100)
        echo "<tr class=\"resign_tr\">\n";
    else
        echo "<tr>\n";
    echo "    <td><input type=\"text\" readonly=\"readonly\" id=\"txtEmId\""
        . " class=\"input-box\" value=\"" . $row["em_id"] . "\"/></td>\n";
    echo "    <td><input type=\"text\" id=\"txtEmName\" class=\"input-box\""
        . " maxlength=8 value=\"" . $row["em_name"] . "\"/></td>\n";
    echo "    <td><select id=\"selDepart\" class=\"input-list\">\n";
    foreach ($lstDepart as $depart) {
        echo "       <option value=\"" . $depart["depart_id"] . "\"";
        if ($depart["depart_id"] == $row["em_depart_id"]) 
            echo " selected=\"selected\"";
        echo ">" . $depart["depart_name"] . "</option>\n";
    }

    echo "    </select></td>\n";
    echo "    <td><input type=\"text\" id=\"txtClass\" class=\"input-s-box\""
        . " maxlength=1 value=\"" . $row["em_class"] . "\"/></td>\n";	
    echo "    <td><input type=\"text\" id=\"txtEnter\" class=\"input-box\""
        . " maxlength=10 value=\"" . $row["em_enter"] . "\"/></td>\n";	
    echo "    <td><input type=\"text\" id=\"txtBirth\" class=\"input-box\""
        . " maxlength=10 value=\"" . $row["em_birth"] . "\"/></td>\n";	
    echo "    <td><select id=\"selGender\" class=\"input-list\">";
    
    echo "        <option value=\"男\"";
    if ($row["em_gender"] == "男") echo " selected";
    echo ">男</option>\n";	
    
    echo "        <option value=\"女\"";
    if ($row["em_gender"] == "女") echo " selected";
    echo ">女</option>\n";	
    echo "    </select></td>\n";
    echo "    <td><button type=\"button\""
        . " onclick=\"doDelete('" . $row["em_id"] . "')\">Delete</button>\n";
    echo "        <button type=\"button\""
        . " onclick=\"doModify('" . $row["em_id"] . "')\">Modify</button>\n";
    echo "    </td>\n";

    echo "</tr>\n";
    echo "</form>\n";
}
?>
</table>
<div style="clear:both;">&nbsp;</div>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:right;">
<a href="/hr">返回</a></div>
<?php
// show current employee information
$iSQL->close();
?>
</body>
</html>
